package com.price.sample.http

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView.Adapter
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.bumptech.glide.Glide
import com.price.common.extend.context
import com.price.sample.http.beans.Article
import com.zp.common.R

class ArticleAdapter:Adapter<ArticleAdapter.MyviewHolder>() {
    var datas:MutableList<Article> = mutableListOf()
    fun setData(list:List<Article>?){
        if(list!=null) {
            datas.addAll(list)
            notifyDataSetChanged()
        }
    }
    inner class MyviewHolder(itemView: View):ViewHolder(itemView) {
        val tvItem:TextView=itemView.findViewById(R.id.tv_item)
    }
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyviewHolder {
        val view= LayoutInflater.from(parent.context).inflate(R.layout.item_article,parent,false)
        return MyviewHolder(view)
    }

    override fun getItemCount(): Int =datas.size

    override fun onBindViewHolder(holder: MyviewHolder, position: Int) {
        val bean=datas[position]
        holder.tvItem.text=bean.title
    }
}

